package com.by.controller;

import com.by.entity.SysMenu;
import com.by.model.Result;
import com.by.service.SysMenuService;
import com.by.util.AuthUtils;
import com.by.vo.MenuAndPermsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @author ServivE
 * @version 0.1
 * @className SysMenuController
 * @description
 * @date 2024/12/9 15:24
 * @since jdk17
 */
@Api(tags = "系统权限接口管理")
@RestController
@RequestMapping("sys/menu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation("查询登录用户的菜单和权限")
    @GetMapping("nav")
    public Result<MenuAndPermsVo> loadUserMenuAndPerms() {
        // 获取当前登录用户ID
        Long loginUserId = AuthUtils.getLoginUserId();
        // 查询当前登录用户的权限集合
        Set<String> perms = AuthUtils.getPerms();
        // 根据用户ID查询菜单集合
        Set<SysMenu> sysMenus = sysMenuService.queryUserMenus(loginUserId);
        // 创建菜单和权限集合对象
        MenuAndPermsVo menuAndPermsVo = new MenuAndPermsVo(sysMenus, perms);
        return Result.success(menuAndPermsVo);
    }
}
